WPS Office.apk(点击下载) / aazp.java


package defpackage;

import cn.wps.core.runtime.Platform;
import com.mopub.nativeads.KS2SEventNative;
import java.io.Closeable;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Date;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.concurrent.locks.ReentrantReadWriteLock;

/* renamed from: aazp  reason: default package */
public abstract class aazp implements Closeable {
    protected static final aazs CBs = aazs.READ_WRITE;
    private static final String TAG = null;
    protected abak CBA;
    protected abah CBB;
    protected abag CBC;
    protected ArrayList<aazn> CBD;
    protected abaf CBE;
    protected String CBF;
    protected File CBG;
    protected vpv CBH;
    aazs CBt;
    protected aazu CBu;
    protected aazu CBv;
    protected aazy CBw;
    protected Hashtable<abae, abal> CBx;
    protected abal CBy;
    protected Hashtable<abae, abam> CBz;
    protected boolean dsq = false;
    protected OutputStream xlW;

    aazp(aazs aazs) {
        if (getClass() != abac.class) {
            throw new IllegalArgumentException("PackageBase may not be subclassed");
        }
        this.CBD = new ArrayList<>();
        this.CBx = new Hashtable<>(5);
        this.CBz = new Hashtable<>(2);
        try {
            this.CBz.put(new abae("application/vnd.openxmlformats-package.core-properties+xml"), new abaz());
            this.CBz.put(new abae("application/vnd.openxmlformats-officedocument.extended-properties+xml"), new abay());
            this.CBz.put(new abae("application/vnd.openxmlformats-officedocument.custom-properties+xml"), new abax());
            this.CBy = new abaq();
            this.CBx.put(new abae("application/vnd.openxmlformats-package.core-properties+xml"), new abav());
            this.CBt = aazs;
        } catch (aazi e) {
            throw new aazl("Package.init() : this exception should never happen, if you read this message please send a mail to the developers team. : " + e.getMessage());
        }
    }

    public static aazp a(String str, aazs aazs) throws aazi {
        abac abac = new abac(str, aazs);
        if (abac.CBu == null && aazs != aazs.WRITE) {
            abac.hdd();
        }
        abac.CBF = new File(str).getAbsolutePath();
        return abac;
    }

    private aazy ahM(String str) {
        hcZ();
        hdf();
        return new aazy(this.CBw, str);
    }

    public static aazp am(InputStream inputStream) throws aazi, IOException {
        abac abac = new abac(inputStream, aazs.READ_WRITE);
        if (abac.CBu == null) {
            abac.hdd();
        }
        return abac;
    }

    public static aazp bF(File file) throws IOException {
        if (file == null || (file.exists() && file.isDirectory())) {
            throw new IllegalArgumentException(KS2SEventNative.SCHEME_FILE);
        }
        abac abac = new abac();
        abac.CBF = file.getAbsolutePath();
        File bI = abai.bI(file);
        if (!bI.exists()) {
            bI.mkdirs();
        }
        abac.CBG = File.createTempFile(bG(bI), ".tmp", bI);
        abac.CBH = new vpv(new FileOutputStream(abac.CBG));
        try {
            abac.CBE = new aban(null, abac);
            abac.CBE.b(aazz.f(aazz.CCt), "application/vnd.openxmlformats-package.relationships+xml");
            abac.CBE.b(aazz.aib("/default.xml"), "application/xml");
            abac.CBA = new abak(abac, aazz.CCy);
            abac.CBA.ahR("WPS Office");
            abac.CBA.a(new abbb<>(new Date()));
            return abac;
        } catch (aazi e) {
            throw new IllegalStateException(e);
        }
    }

    private static String bG(File file) {
        File file2;
        do {
            file2 = new File(file.getAbsolutePath() + File.separator + "WPS_" + System.nanoTime());
        } while (file2.exists());
        return abai.bJ(file2.getAbsoluteFile());
    }

    private static String c(aazt aazt) {
        FileOutputStream fileOutputStream;
        Throwable th;
        File file;
        FileOutputStream fileOutputStream2 = null;
        try {
            InputStream inputStream = aazt.getInputStream();
            if (inputStream == null) {
                lul.a(null);
                return null;
            }
            aazv hdn = aazt.hdn();
            if (hdn == null) {
                lul.a(null);
                return null;
            }
            String name = hdn.getName();
            if (name == null) {
                lul.a(null);
                return null;
            }
            file = Platform.createTempFile(name.replace("/", ""), "");
            fileOutputStream = new FileOutputStream(file);
            try {
                byte[] bArr = new byte[4096];
                while (true) {
                    int read = inputStream.read(bArr);
                    if (-1 == read) {
                        break;
                    }
                    fileOutputStream.write(bArr, 0, read);
                }
                lul.a(fileOutputStream);
            } catch (IOException e) {
                e = e;
                try {
                    hm.e(TAG, "IOException", e);
                    lul.a(fileOutputStream);
                    file = null;
                    return file.getAbsolutePath();
                } catch (Throwable th2) {
                    th = th2;
                    fileOutputStream2 = fileOutputStream;
                    lul.a(fileOutputStream2);
                    throw th;
                }
            }
            return file.getAbsolutePath();
        } catch (IOException e2) {
            e = e2;
            fileOutputStream = null;
            hm.e(TAG, "IOException", e);
            lul.a(fileOutputStream);
            file = null;
            return file.getAbsolutePath();
        } catch (Throwable th3) {
            th = th3;
            lul.a(fileOutputStream2);
            throw th;
        }
    }

    private boolean c(aazv aazv) {
        return a(aazv) != null;
    }

    private void hdf() {
        if (this.CBw == null) {
            try {
                this.CBw = new aazy(this);
            } catch (aazi e) {
                hm.e(TAG, "InvalidFormatException: " + e);
                this.CBw = new aazy();
            }
        }
    }

    private void save(OutputStream outputStream) throws IOException {
        hcY();
        j(outputStream);
    }

    public final aazt a(aazv aazv) {
        hcZ();
        if (aazv == null) {
            throw new IllegalArgumentException("partName");
        }
        if (this.CBu == null) {
            try {
                hdd();
            } catch (aazi e) {
                hm.e(TAG, "InvalidFormatException", e);
                return null;
            }
        }
        return e(aazv);
    }

    public final aazt a(aazv aazv, String str) {
        return a(aazv, str, true);
    }

    /* access modifiers changed from: package-private */
    public final aazt a(aazv aazv, String str, boolean z) {
        hcY();
        if (aazv == null) {
            throw new IllegalArgumentException("partName");
        } else if (str == null || str.equals("")) {
            throw new IllegalArgumentException("contentType");
        } else if (this.CBu.containsKey(aazv) && !((aazt) this.CBu.get(aazv)).CBU) {
            throw new aazj("A part with the name '" + aazv.getName() + "' already exists : Packages shall not contain equivalent part names and package implementers shall neither create nor recognize packages with equivalent part names. [M1.12]");
        } else if (!str.equals("application/vnd.openxmlformats-package.core-properties+xml") || this.CBA == null) {
            aazt b = b(aazv, str, z);
            this.CBE.b(aazv, str);
            this.CBu.put(aazv, b);
            this.dsq = true;
            return b;
        } else {
            throw new aazj("OPC Compliance error [M4.1]: you try to add more than one core properties relationship in the package !");
        }
    }

    public final aazt a(aazx aazx) {
        hdf();
        Iterator<aazx> it = this.CBw.iterator();
        while (it.hasNext()) {
            aazx next = it.next();
            if (next.eWp.equals(aazx.eWp)) {
                try {
                    return a(aazz.f(next.hds()));
                } catch (aazi e) {
                    hm.e(TAG, "InvalidFormatException: " + e);
                }
            }
        }
        return null;
    }

    public final aazx a(aazv aazv, abab abab, String str, String str2) {
        if (str.equals("http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties") && this.CBA != null) {
            throw new aazj("OPC Compliance error [M4.1]: can't add another core properties part ! Use the built-in package method instead.");
        } else if (aazv.CBY) {
            throw new aazj("Rule M1.25: The Relationships part shall not have relationships to any other part.");
        } else {
            hdf();
            aazx a = this.CBw.a(aazv.CBX, abab, str, null);
            this.dsq = true;
            return a;
        }
    }

    public final ArrayList<aazt> ahK(String str) {
        ArrayList<aazt> arrayList = new ArrayList<>();
        Iterator<aazx> it = ahL(str).iterator();
        while (it.hasNext()) {
            arrayList.add(a(it.next()));
        }
        return arrayList;
    }

    public final aazy ahL(String str) {
        hcZ();
        if (str != null) {
            return ahM(str);
        }
        throw new IllegalArgumentException("relationshipType");
    }

    /* access modifiers changed from: protected */
    public abstract aazt b(aazv aazv, String str, boolean z);

    public final void b(aazv aazv) {
        aazt a;
        hcY();
        if (aazv == null || !c(aazv)) {
            throw new IllegalArgumentException("partName");
        }
        if (this.CBu.containsKey(aazv)) {
            ((aazt) this.CBu.get(aazv)).CBU = true;
            d(aazv);
            this.CBu.remove(aazv);
        } else {
            d(aazv);
        }
        this.CBE.g(aazv);
        if (aazv.CBY) {
            try {
                aazv f = aazz.f(aazz.e(aazv.CBX));
                if (f.CBX.equals(aazz.CCB)) {
                    if (this.CBw != null) {
                        this.CBw.clear();
                        this.dsq = true;
                    }
                } else if (!(!c(f) || (a = a(f)) == null || a.CBV == null)) {
                    a.CBV.clear();
                }
            } catch (aazi e) {
                return;
            }
        }
        this.dsq = true;
    }

    public final void bH(File file) throws IOException {
        if (file == null) {
            throw new IllegalArgumentException("targetFile");
        }
        hcY();
        save(this.CBH);
    }

    @Override // java.io.Closeable, java.lang.AutoCloseable
    public void close() throws IOException {
        if (this.CBt == aazs.READ) {
            hdh();
            this.CBE.clearAll();
            apb.IL();
            aoy.IL();
            apc.IL();
            return;
        }
        ReentrantReadWriteLock reentrantReadWriteLock = new ReentrantReadWriteLock();
        try {
            reentrantReadWriteLock.writeLock().lock();
            if (this.CBF != null && !"".equals(this.CBF.trim())) {
                hdg();
            } else if (this.xlW != null) {
                save(this.xlW);
                this.xlW.close();
            }
        } finally {
            reentrantReadWriteLock.writeLock().unlock();
            if (this.CBE != null) {
                this.CBE.clearAll();
            }
            apb.IL();
            aoy.IL();
            apc.IL();
        }
    }

    /* access modifiers changed from: protected */
    public abstract void d(aazv aazv);

    /* access modifiers changed from: protected */
    public abstract aazt e(aazv aazv);

    public final vpv hcW() {
        return this.CBH;
    }

    public final File hcX() {
        return this.CBG;
    }

    /* access modifiers changed from: package-private */
    public final void hcY() throws aazj {
        if (this.CBt == aazs.READ) {
            throw new aazj("Operation not allowed, document open in read only mode!");
        }
    }

    /* access modifiers changed from: package-private */
    public final void hcZ() throws aazj {
        if (this.CBt == aazs.WRITE) {
            throw new aazj("Operation not allowed, document open in write only mode!");
        }
    }

    public final aazw hda() throws aazi {
        hcZ();
        if (this.CBA == null) {
            this.CBA = new abak(this, aazz.CCy);
        }
        return this.CBA;
    }

    public final aazo hdb() throws aazi {
        hcZ();
        if (this.CBB == null) {
            this.CBB = new abah(this, aazz.CCz);
        }
        return this.CBB;
    }

    public final aazm hdc() throws aazi {
        hcZ();
        if (this.CBC == null) {
            this.CBC = new abag(this, aazz.CCA);
        }
        return this.CBC;
    }

    public final ArrayList<aazt> hdd() throws aazi {
        String str;
        hcZ();
        if (this.CBu == null) {
            aazt[] hdi = hdi();
            this.CBv = this.CBu;
            this.CBu = new aazu();
            boolean z = false;
            for (aazt aazt : hdi) {
                if (this.CBu.containsKey(aazt.CBR)) {
                    throw new aazi("A part with the name '" + aazt.CBR + "' already exist : Packages shall not contain equivalent part names and package implementers shall neither create nor recognize packages with equivalent part names. [M1.12]");
                }
                aazv hdn = aazt.hdn();
                String name = hdn == null ? null : hdn.getName();
                if (name != null && name.startsWith("/customXml/item") && abgb.COj.getContentType().equals(aazt.getContentType())) {
                    try {
                        String c = c(aazt);
                        if (c != null) {
                            aazy hde = aazt.hde();
                            if (hde.size() > 0) {
                                vpn hds = hde.azs(0).hds();
                                aazt aazt2 = (aazt) this.CBv.get(hds == null ? null : aazz.f(hds));
                                String contentType = aazt2 == null ? null : aazt2.getContentType();
                                if (contentType != null && abgb.COi.getContentType().equals(contentType)) {
                                    str = c(aazt2);
                                    this.CBD.add(new aazn(c, str));
                                }
                            }
                            str = null;
                            this.CBD.add(new aazn(c, str));
                        }
                    } catch (Throwable th) {
                    }
                }
                if (aazt.getContentType().equals("application/vnd.openxmlformats-package.core-properties+xml")) {
                    if (!z) {
                        z = true;
                    }
                }
                abam abam = this.CBz.get(aazt.CBS);
                if (abam != null) {
                    try {
                        aazt a = abam.a(new abba(this, aazt.CBR), aazt.getInputStream());
                        this.CBu.put(a.CBR, a);
                        if (a instanceof abak) {
                            this.CBA = (abak) a;
                        } else if (a instanceof abah) {
                            this.CBB = (abah) a;
                        } else if (a instanceof abag) {
                            this.CBC = (abag) a;
                        }
                    } catch (IOException e) {
                        hm.e(TAG, "Unmarshall operation : IOException for " + aazt.CBR);
                    } catch (aazj e2) {
                        throw new aazi(e2.getMessage());
                    }
                } else {
                    try {
                        this.CBu.put(aazt.CBR, aazt);
                    } catch (aazj e3) {
                        throw new aazi(e3.getMessage());
                    }
                }
            }
        }
        return new ArrayList<>(this.CBu.values());
    }

    public final aazy hde() {
        return ahM(null);
    }

    /* access modifiers changed from: protected */
    public abstract void hdg() throws IOException;

    /* access modifiers changed from: protected */
    public abstract void hdh();

    /* access modifiers changed from: protected */
    public abstract aazt[] hdi() throws aazi;

    public final ArrayList<aazn> hdj() {
        return this.CBD;
    }

    /* access modifiers changed from: protected */
    public abstract void j(OutputStream outputStream) throws IOException;
}